from django.contrib.auth.models import User
from django.db import models

# Create your models here.
from utils.modelsMixin import ModelsSetMixin


class Label(models.Model):
    name = models.CharField('标签名', max_length=20, unique=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        db_table = 'label'
        verbose_name = '标签'
        verbose_name_plural = verbose_name

    def __str__(self):
        return f'{self.name}-{self.user}'


class Topic(ModelsSetMixin):
    # id，subject（题目内容), score(分值)，type(类型)，options（选项），answer（答案），
    # label(关联字段，关联标签表Label)， user（出题人，关联字段，关联User表）
    TYPE_CHOICE = (
        (0, '单选题'),
        (1, '多选题'),
        (2, '填空题'),
        (3, '判断题'),
        (4, '问答题'),
    )
    subject = models.TextField('题目内容')
    score = models.FloatField('分值')
    type = models.IntegerField('类型', choices=TYPE_CHOICE)
    description = models.TextField('题目描述', null=True, blank=True)
    answer = models.TextField('答案')

    # 一个标签下有多道题，一个用户出多个题
    label = models.ForeignKey(Label, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        db_table = 'topic'
        verbose_name = '题目'
        verbose_name_plural = verbose_name
        ordering = ['id']  # 设置默认排序字段
